#include "pch.h"
#include "PreviewContentProvider.h"

PreviewContentProvider::PreviewContentProvider(PreviewBase^ controller) :
	m_controller(controller)
{
}

HRESULT PreviewContentProvider::Connect(_In_ IDrawingSurfaceRuntimeHostNative* host, _In_ ID3D11Device1* device)
{
	m_host = host;
	m_host->AddRef();

	return m_controller->Connect(host, device);
}

void PreviewContentProvider::Disconnect()
{
	m_controller->Disconnect();
	SafeRelease(&m_host);
}

HRESULT PreviewContentProvider::PrepareResources(_In_ const LARGE_INTEGER* presentTargetTime, _Inout_ DrawingSurfaceSizeF* desiredRenderTargetSize)
{
	return m_controller->PrepareResources(presentTargetTime, desiredRenderTargetSize);
}

HRESULT PreviewContentProvider::Draw(_In_ ID3D11Device1* device, _In_ ID3D11DeviceContext1* context, _In_ ID3D11RenderTargetView* renderTargetView)
{
	HRESULT hr = m_controller->Draw(device, context, renderTargetView);
	if (SUCCEEDED(hr))
	{
		hr = m_host->RequestAdditionalFrame();
	}

	return hr;
}